import math
import numpy as np
import matplotlib.pyplot as plt

# arange 可以生成小数的等差数列
A = np.arange(0.1, 1, 0.2)
print(type(A))
print(A)

B = np.linspace(-1, 1, 5)
print(type(B))
print(B)

# 例题：绘制 y = sin（x）在 [0,2排]的函数曲线
plt.switch_backend('TkAgg')  # 设置后端为TkAgg
x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)
plt.plot(x, y, 'r--')
plt.show()

# 习题：绘制如下函数曲线，其他 search_text 属于 [0,2pi]

a = np.linspace(0, 2 * np.pi, 200)
x = 16 * (np.sin(a)) ** 3
y = 13 * np.cos(a) - 5 * np.cos(2 * a) - 2 * np.cos(3 * a) - np.cos(4 * a)
print(x)
print(y)
plt.plot(x, y, "r")
plt.axis([-25, 25, -20, 15])
plt.show()


# 用 numpy 绘制炸弹曲线轨迹

def bomb_curve_trajectory(h, v0, g, n=50):
    t_max = (2 * h / g) ** 0.5
    T = np.linspace(0, t_max, n)
    xt = v0 * T
    yt = h - 0.5 * g * T ** 2
    plt.plot(xt, yt, "ro-")
    plt.grid('on')
    plt.axis([0, 5000, 0, h])
    plt.show()


h, v0, g = 3000, 200, 9.8
bomb_curve_trajectory(h, v0, g, n=200)

tizhong = 70
shengao = 1.69
BMI = tizhong / (shengao ** 2)
print(BMI)  # BMI应该在18.5-23.9


